﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace UbwApplication
{
    static class Program
    {
        static AppDomain _appDomain;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            _appDomain = AppDomain.CurrentDomain;
            _appDomain.UnhandledException += new UnhandledExceptionEventHandler(_appDomain_UnhandledException);

            Application.Run(new MainForm());
        }

        static void _appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            recordException(e.ExceptionObject as Exception);
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            recordException(e.Exception);
        }

        static void recordException(Exception ex)
        {
            if (ex != null)
            {
                string eStr = ex.ToString();
                string path = Path.GetDirectoryName(Application.ExecutablePath) + "\\ErrorLog.txt";

                System.IO.File.AppendAllText(path, eStr);
            }
        }

    }
}
